<template>
    <div>
      <h1>数据导出</h1>
      <button @click="exportData">导出数据</button>
    </div>
  </template>
  
  <script>
  
  export default {
    methods: {
      async exportData() {
        try {
          const response = await this.$request.get('/tpa/api/export_data/');
          const blob = new Blob([JSON.stringify(response, null, 2)], { type: 'application/json' });
          const url = window.URL.createObjectURL(blob);
          const a = document.createElement('a');
          a.href = url;
          a.download = 'data.json';
          a.click();
          window.URL.revokeObjectURL(url);
        } catch (error) {
          alert('导出数据失败');
        }
      },
    },
  };
  </script>